package com.hawk.eye.client.async;

import com.hawk.eye.client.async.task.HawkEyeTask;
import com.hawk.eye.client.constant.HawkEyeConstant;
import com.hawk.eye.client.util.ThreadUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @className: TaskExecutor
 * @description: 任务执行器
 * @author: salad
 * @date: 2023/9/16
 **/
public class TaskExecutor {

    private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(1,new NamedThreadFactory(HawkEyeConstant.PULL_THREAD_PREFIX));

    public static void execute(HawkEyeTask hawkEyeTask) {
        EXECUTOR_SERVICE.execute(hawkEyeTask);
    }

    public static Future<?> submit(HawkEyeTask hawkEyeTask) {
        return EXECUTOR_SERVICE.submit(hawkEyeTask);
    }

    public static void shutdown() {
        ThreadUtil.shutdownAndAwaitTermination(EXECUTOR_SERVICE);
    }

}
